package edu.tgc.service.qrtz;

import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;

import edu.tgc.entity.qrtz.QrtzTrigger;

public class QrtzTriggerService {

    protected SchedulerFactory schedulerFactory;

    public void deleteTrigger(QrtzTrigger qrtzTrigger) {
        try {
            Scheduler scheduler = this.schedulerFactory.getScheduler();
            scheduler.unscheduleJob(qrtzTrigger.getTriggerKey());
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }

    // 暂停单个trigger
    public void pause(QrtzTrigger qrtzTrigger) {
        Scheduler scheduler;
        try {
            scheduler = this.schedulerFactory.getScheduler();
            scheduler.pauseTrigger(qrtzTrigger.getTriggerKey());
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }

    // 恢复单个trigger
    public void resume(QrtzTrigger qrtzTrigger) {
        Scheduler scheduler;
        try {
            scheduler = this.schedulerFactory.getScheduler();
            scheduler.resumeTrigger(qrtzTrigger.getTriggerKey());
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
}
